package demo0506;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Test {
    public static void main(String[] args) throws IOException {
        //变量存储数据
        String data="劳动节快乐";
        FileOutputStream outputStream=new FileOutputStream("1.txt");
        byte[] bytes=data.getBytes();
        //需要把字符换成字节
        outputStream.write(bytes);

//使用FileInputStream从文件中读取字节数据并输出到控制台:劳动节快乐=>一个个获取
        FileInputStream inputStream = new FileInputStream("1.txt");
        //创建一个字节数组
        byte[] buffer=new byte[1024];
        StringBuilder conten=new StringBuilder();
        int length;
        while((length=inputStream.read(buffer))!=-1){
            conten.append(new String(buffer,0,length,StandardCharsets.UTF_8));
        }
        System.out.println(conten.toString());

    }
}
